package com.student.Activitys.activity;

import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.view.View;
import android.widget.TextView;

import com.student.Activitys.R;
import com.student.Activitys.activity.base.BaseActivity;
import com.student.Activitys.utils.Constant;
import com.student.Activitys.utils.JumperUtils;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 项目名称：智慧校园学生端
 * 类描述：选择学生身份 activity
 * 创建人：张飞祥
 * 创建时间：2017/10/31 13:51
 * 修改人：张飞祥
 * 修改时间：2017/10/31 13:51
 * 修改备注：
 */
public class IdentityActivity extends BaseActivity {
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_identity_new_student)
    TextView tvIdentityNewStudent;
    @Bind(R.id.tv_identity_stay_student)
    TextView tvIdentityStayStudent;
    @Bind(R.id.app_bar_layout)
    AppBarLayout appBarLayout;

    //当前身份
    private String identity = null;

    @Override
    protected void initUI() {
        setContentView(R.layout.act_identity);
    }

    @Override
    protected void initData() {
        //标题
        tvTitle.setText("身份选择");
        //标题文字颜色
        tvTitle.setTextColor(Color.BLACK);
        //标题背景
        appBarLayout.setBackgroundResource(R.color.color_bg_white);
        //获取 当前身份标识
        identity = mACache.getAsString(Constant.USER_IDENTITY);
        //如果 本地储存的 身份不为空 则跳转登录,并销毁本页面
        if (identity!=null && !identity.equals("")){
            JumperUtils.JumpTo(IdentityActivity.this,LoginActivity.class);
            finish();
        }
    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.tv_identity_new_student,R.id.tv_identity_stay_student})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_identity_new_student:      //新生
                identity = tvIdentityNewStudent.getText().toString();
                //跳转登陆
                initLogin(identity);
                break;
            case R.id.tv_identity_stay_student:    //在校生
                identity = tvIdentityStayStudent.getText().toString();
                //跳转登陆
                initLogin(identity);
                break;
        }
    }

    /**
     * 跳转登陆事件
     */
    private void initLogin(String state) {
        //保存当前选择的身份到本地
        mACache.put(Constant.USER_IDENTITY,state);
        JumperUtils.JumpTo(IdentityActivity.this,LoginActivity.class);
    }

    @Override
    protected void getNotData() {

    }

    /**
     * 屏蔽 back 键
     */
    @Override
    public void onBackPressed() {
//        super.onBackPressed();
    }

}
